/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.strategy;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.anwen.mongo.conditions.query.LambdaQueryChainWrapper;
import com.anwen.mongo.service.impl.ServiceImpl;
import com.comac.ins.isfd.domain.IsfdAnalysis;

@Component
public class AnalysisCalculation extends ServiceImpl<IsfdAnalysis> implements TableCalculationStrategy {

    @Override
    public Long calculate(Date startTime, Date endTime) {
        LambdaQueryChainWrapper<IsfdAnalysis> queryChainWrapper = this.lambdaQuery();

        if (startTime != null || endTime != null) {
            if (startTime != null) {
                queryChainWrapper.gte(IsfdAnalysis::getCreateTime, startTime);
            }
            if (endTime != null) {
                queryChainWrapper.lte(IsfdAnalysis::getCreateTime, endTime);
            }
        }

        long count = this.count(queryChainWrapper);


        return count;
    }

}
